package com.quasar.hpatient.view.adapter;

import android.text.style.ForegroundColorSpan;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.makeramen.roundedimageview.RoundedImageView;
import com.quasar.hpatient.MainAppliaction;
import com.quasar.hpatient.R;
import com.quasar.hpatient.model.medicalmodel.FriendsData;
import com.quasar.hpatient.network.RetrofitConnection;
import com.quasar.hpatient.utils.Spanny;
import com.quasar.hpatient.utils.TimeZoneUtil;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * 我的好友消息
 * Created by Xu on 2017/10/16.
 */

public class NewsFriendAdapter extends BaseQuickAdapter<FriendsData, BaseViewHolder>{

    private BaseViewHolder helper;

    public NewsFriendAdapter() {
        super(R.layout.friend_item_follow);
    }

    @Override
    protected void convert(BaseViewHolder helper, final FriendsData item) {
        this.helper=helper;

        //真实姓名
        if(item.getRealName()!=null && item.getRealName().length()>0){
            helper.setText(R.id.name,item.getRealName());
        }
        //性别
        String Sex;
        //性别
        if(item.getSex()==0){
            Sex="男";
        }else{
            Sex="女";
        }
        Spanny spanny = new Spanny();
        spanny.append("性别：", new ForegroundColorSpan(color(R.color.btcolor)));
        spanny.append("" + Sex, new ForegroundColorSpan(color(R.color.textcolor)));
        helper.setText(R.id.tv_job_title,spanny);

        //出生日期
        String dayTime;
        if(item.getBirthday()!=null && item.getBirthday().length()>0){

            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
            Date date = null;
            try {
                date = sdf.parse(item.getBirthday());
            } catch (ParseException e) {
                e.printStackTrace();
            }
            int age = TimeZoneUtil.getAge(date);
            dayTime=age+"";
        }else{
            dayTime="未知";
        }

        //头像

        RoundedImageView headimg=helper.getView(R.id.headimg);
        if(item.getCover()!=null && item.getCover().length()>0){
            Glide.with(mContext).load(RetrofitConnection.PHOTOURL+item.getCover()).into(headimg);
        }
        Spanny spanny1 = new Spanny();
        spanny1.append("年龄：", new ForegroundColorSpan(color(R.color.btcolor)));
        spanny1.append("" + dayTime, new ForegroundColorSpan(color(R.color.textcolor)));
        helper.setText(R.id.tv_hospital,spanny1);
        //添加按钮
        helper.setVisible(R.id.tv_Refuse,true);

        //添加
        helper.addOnClickListener(R.id.tv_addto);
        //拒绝
        helper.addOnClickListener(R.id.tv_Refuse);
    }

    private int color(int value) {
        return MainAppliaction.getInstance().getResources().getColor(value);
    }
}
